/*
 * @Author: szx
 * @Date: 2022-05-12 13:45:55
 * @LastEditTime: 2022-05-12 13:53:19
 * @Description:
 * @FilePath: \leetcode\面试题\01\06\06.js
 */
/**
 * @param {string} S
 * @return {string}
 */
var compressString = function (s) {
    let res = '',
        cnt = 0,
        tmp = s[0];
    for (let i of s) {
        if (i != tmp) {
            res += tmp + cnt;
            cnt = 0;
            tmp = i;
        }
        cnt++;
    }
    res += tmp + cnt;
    return res.length >= s.length ? s : res;
};
